package storage

import "go-fiber-ip2region/model/ip/response"

type ipInfoList map[string]response.IpInfoReq

var ipList ipInfoList

func getIpInfoList() ipInfoList {
	if ipList == nil {
		ipList = make(ipInfoList)
	}

	return ipList
}

func AddIpInfo(ip string, v response.IpInfoReq) {
	list := getIpInfoList()
	list[ip] = v
}

func GetIpInfo(ip string) response.IpInfoReq {
	return ipList[ip]
}

func EmptyIpGroup() {
	// go 没有提供直接清空map的方法，我们可以通过新建一个map来实现赋值操作
	// go 自带的垃圾回收比写一个清空函数高
	ipList = make(ipInfoList)
}
